<?php
  session_start();
  if ($_POST) {
    $retorno = $_POST["pageBack"];
    header("Location: $retorno");
    include("config/login-defs.php");
    $formAction = $_POST["formAction"];
    if ($formAction == "excluir") {
      //$query = "UPDATE funcionario SET status = 'Inativo' WHERE id_funcionario = " . $_POST["keyValue"] ;	  
      $data = mysql_query($query) or print(mysql_error());
    } else if ($formAction == "alterar") {
      $id = $_POST["id"];
      $query = 'UPDATE departamento SET nome = "' . $_POST["fldNome"] . '", 
		                                sigla = "' . $_POST["fldSigla"] . '", 
									    id_depto_superior = "' . $_POST["cbDeptoSuperior"] . '", 
										id_conta = "' . $_POST["cbConta"] . '" ' .
                    'WHERE id_depto = ' . $_POST["id"];
      $data = mysql_query($query) or print(mysql_error());
    } else if ($formAction == "inserir") {
      // SQL Insert CMS.
      $query = 'INSERT INTO departamento (nome, sigla, id_depto_superior, id_conta, status)' .
                  ' VALUES ("' . $_POST["fldNome"] . '","' 
				               . $_POST["fldSigla"] .'","'
							   . $_POST["cbDeptoSuperior"] . '","'
							   . $_POST["cbConta"] . '","'
							   . $_POST["cbStatus"] . '")';
      $data = mysql_query($query) or print(mysql_error());	  
    }
  }
?>